package ru.gelin.android.multiplier;

import android.app.Fragment;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;

public class HistoryFragment extends ListFragment {

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);    //To change body of overridden methods use File | Settings | File Templates.
        MainActivity activity = (MainActivity)getActivity();
        setListAdapter(new OperationsHistoryAdapter(activity, activity.getHistory()));
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        OperationsHistoryItem item = (OperationsHistoryItem)getListAdapter().getItem(position);
        MainActivity activity = (MainActivity)getActivity();
        activity.getHistory().add(item.operation);
        getActivity().getActionBar().setSelectedNavigationItem(0);  //TODO refactor the number
    }

}
